import 'package:bxultimate/app/router/router_name.dart';
import 'package:bxultimate/app/theme/app_theme.dart';
import 'package:bxultimate/app/theme/gaps.dart';
import 'package:bxultimate/data/request/application_request.dart';
import 'package:bxultimate/data/request/organization_request.dart';
import 'package:bxultimate/data/store/config_store.dart';
import 'package:bxultimate/domain/application/organization/OrganizationDto.dart';
import 'package:bxultimate/resources/assets.dart';
import 'package:bxultimate/widgets/mk_load_image.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';

class MyOrg extends StatefulWidget {
  const MyOrg({super.key});

  @override
  State<MyOrg> createState() => _MyOrgState();
}

class _MyOrgState extends State<MyOrg> {
  List<OrganizationDto> listData = [];

  getData() async {
    listData.addAll(await OrganizationRequest.getOrganizationList());
    setState(() {});
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getData();
  }

  @override
  Widget build(BuildContext context) {
    return ListView.builder(
      itemCount: listData.length,
      itemBuilder: (context, index) {
        return GestureDetector(
          onTap: () {
            Get.toNamed(RouterName.organizationChat,arguments: {
              "orgId": listData[index].id,
              "areaLsgx": listData[index].areaLsgx,
              "attributionCode": listData[index].attributionCode,
            });
          },
          child: _buildMyOrganization(listData[index]),
        );
      },
    );
  }

  _buildMyOrganization(OrganizationDto organizationDto) {
    return Container(
      margin: EdgeInsets.only(bottom: AppTheme.iDefaultPadding),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(AppTheme.iDefaultRadius),
      ),
      child: Column(
        children: [
          Padding(
            padding: EdgeInsets.all(
              AppTheme.iDefaultPadding,
            ),
            child: Row(
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                organizationDto.teamHeadImgUrl == null
                    ? ClipRRect(
                        borderRadius: BorderRadius.circular(10),
                        child: MkLoadImage(
                          Assets.imagesIcon,
                          width: 60,
                          height: 60,
                        ),
                      )
                    : ClipRRect(
                        borderRadius: BorderRadius.circular(10),
                        child: MkLoadImage(
                          ConfigStore.to.baseFileUrl +
                              organizationDto.teamHeadImgUrl!,
                          width: 60,
                          height: 60,
                        ),
                      ),
                Gaps.hGap12,
                Column(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text('${organizationDto.name}',
                        style: TextStyle(
                            fontWeight: FontWeight.bold, fontSize: 16)),
                    Gaps.vGap8,
                    Row(
                      children: [
                        organizationDto.typeName == ''
                            ? SizedBox()
                            : TDTag(
                                '${organizationDto.typeName}',
                                theme: TDTagTheme.warning,
                                isOutline: true,
                              ),
                        Gaps.hGap8,
                        organizationDto.teamLevelName == ''
                            ? SizedBox()
                            : TDTag(
                                '${organizationDto.teamLevelName}',
                                theme: TDTagTheme.warning,
                                isOutline: true,
                              ),
                      ],
                    )
                  ],
                )
              ],
            ),
          ),
          // Container(
          //   margin: EdgeInsets.all(AppTheme.iDefaultPadding / 2),
          //   decoration: BoxDecoration(color: Color(0xFFF5F5F5)),
          //   padding: EdgeInsets.all(AppTheme.iDefaultPadding),
          //   child: Row(
          //     mainAxisAlignment: MainAxisAlignment.start,
          //     crossAxisAlignment: CrossAxisAlignment.start,
          //     children: [
          //       TDTag(
          //         '投票统计',
          //         theme: TDTagTheme.success,
          //         size: TDTagSize.medium,
          //       ),
          //       Gaps.hGap8,
          //       Expanded(
          //         child: Text('霍州市征兵工作组织发来了一条投票统计任务快霍州市征兵工作组织发来了'),
          //       )
          //     ],
          //   ),
          // )
        ],
      ),
    );
  }
}
